#include "Matrix4D.h"


Matrix4D::Matrix4D(void)
{
	initArray();
}

Matrix4D::Matrix4D(const Matrix4D& other){
	initArray();

	for(int i=0; i<4; ++i){
		for(int j=0; j<4; ++j){
			m[i][j] = other.m[i][j];
		}
	}
}

void Matrix4D::initArray(){
	//Allocation du tableau
	m = new double*[4];
	for(int i=0; i<4; ++i)
		m[i] = new double[4];
}

//Place les vecteurs en colonnes
Matrix4D::Matrix4D(Vector4D v1, Vector4D v2, Vector4D v3, Vector4D v4){
	initArray();

	m[0][0] = v1.x; m[0][1] = v2.x; m[0][2] = v3.x; m[0][3] = v4.x;
	m[1][0] = v1.y; m[1][1] = v2.y; m[1][2] = v3.y; m[1][3] = v4.y;
	m[2][0] = v1.z; m[2][1] = v2.z; m[2][2] = v3.z; m[2][3] = v4.z;
	m[3][0] = v1.w; m[3][1] = v2.w; m[3][2] = v3.w; m[3][3] = v4.w;
}

Matrix4D::~Matrix4D(void)
{
	//delete correct ?
	/*for(int i=0; i<4; ++i)
		delete m[i];

	delete m;*/
}

//Produit matrice vecteur
Vector4D* Matrix4D::product(Matrix4D m, Vector4D v){
	return new Vector4D(m.m[0][0]*v.x + m.m[0][1]*v.y + m.m[0][2]*v.z + m.m[0][3]*v.w,
					m.m[1][0]*v.x + m.m[1][1]*v.y + m.m[1][2]*v.z + m.m[1][3]*v.w,
					m.m[2][0]*v.x + m.m[2][1]*v.y + m.m[2][2]*v.z + m.m[2][3]*v.w,
					m.m[3][0]*v.x + m.m[3][1]*v.y + m.m[3][2]*v.z + m.m[3][3]*v.w);
}